﻿using System;
using System.Collections.Generic;
using Dexter.DataTransferObject;
using Dexter.Domain.Model;
using Dexter.Domain.Results;
using Dexter.Repository;

namespace Dexter.Services.Implementation {
	/// <summary>
	/// 	The implementation of <see cref="IPluginService" /> .
	/// </summary>
	public class PluginService : IPluginService {
		readonly IPluginRepository pluginRepository;

		/// <summary>
		/// 	Initializes a new instance of the <see cref="T:System.Object" /> class.
		/// </summary>
		public PluginService(IPluginRepository pluginRepository) {
			this.pluginRepository = pluginRepository;
		}

		#region IPluginService Members

		public IList<Plugin> GetAllPlugins() {
			return pluginRepository.GetAllPlugins();
		}

		public IList<PluginDto> GetAllPluginsDto() {
			return GetAllPlugins().ToDtos();
		}

		public Plugin GetPluginByUniqueKey(Guid uniqueKey) {
			return pluginRepository.GetPluginByIdentifier(uniqueKey);
		}

		public void SaveOrUpdate(Plugin item) {
			pluginRepository.SaveOrUpdate(item);
		}

		public void Delete(Plugin item) {
			pluginRepository.Delete(item);
		}

		public void SaveOrUpdateData(PluginData data) {
			pluginRepository.SaveOrUpdateData(data);
		}

		public PluginData RetrieveDataFromKey(Plugin plugin, string key) {
			return pluginRepository.RetrieveDataFromKey(plugin, key);
		}

		public IPagedResult<PluginData> RetrieveDataFromCreationDate(Plugin plugin, DateTime creationDate, int pageSize, int pageIndex) {
			return pluginRepository.RetrieveDataFromCreationDate(plugin, creationDate, pageSize, pageIndex);
		}

		public IPagedResult<PluginData> RetrieveDataForSpecifiedDateRange(Plugin plugin, DateTime startDate, DateTime endDate, int pageSize, int pageIndex) {
			return pluginRepository.RetrieveDataForSpecifiedDateRange(plugin, startDate, endDate, pageSize, pageIndex);
		}

		#endregion
	}
}